home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2001 March
/
PCWorld_2001-03_cd.bin
/
Software
/
TemaCD
/
classbuild
/
ClassBuilder 2.2 PR405 Setup.exe
/
{app}
/
Include
/
CB_CriticalAvlTree.h
< prev
next >
Wrap
C/C++ Source or Header
|
2000-12-29
|
13KB
|
359 lines
#ifndef CB_CRITICAL_AVLTREE_H
#define CB_CRITICAL_AVLTREE_H
#include <assert.h>
#include "CB_CriticalSection.h"
#include "CB_AvlTree.h"
// defines for include files
#define RELATION_TEMPLATE_CRITICAL_AVLTREE_ACTIVE(member, ClassFrom, NameFrom, ClassTo, NameTo) \
private:\
ClassTo* _top##NameTo;\
int _count##NameTo;\
\
public:\
static CriticalSection& CriticalSection##NameTo()\
{\
static CriticalSection criticalSection##NameTo;\
return criticalSection##NameTo;\
}\
\
void Add##NameTo(ClassTo* item)\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_ADD(member, ClassFrom, NameFrom, ClassTo, NameTo) \
}\
void Remove##NameTo(ClassTo* item)\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_REMOVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
void RemoveAll##NameTo()\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_REMOVEALL(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
void DeleteAll##NameTo()\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_DELETEALL(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
void Replace##NameTo(ClassTo* item, ClassTo* newItem)\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_REPLACE(member, ClassFrom, NameFrom, ClassTo, NameTo) \
}\
ClassTo* GetFirst##NameTo() const\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_GETFIRST(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
ClassTo* GetLast##NameTo() const\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_GETLAST(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
ClassTo* GetNext##NameTo(ClassTo* pos) const\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_GETNEXT(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
ClassTo* GetPrev##NameTo(ClassTo* pos) const\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_GETPREV(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
int Get##NameTo##Count() const\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_GETCOUNT(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
ITERATOR_TEMPLATE_MULTI_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo)
#define RELATION_TEMPLATE_NOFILTER_CRITICAL_AVLTREE_ACTIVE(member, ClassFrom, NameFrom, ClassTo, NameTo) \
private:\
ClassTo* _top##NameTo;\
int _count##NameTo;\
\
public:\
static CriticalSection& CriticalSection##NameTo()\
{\
static CriticalSection criticalSection##NameTo;\
return criticalSection##NameTo;\
}\
\
void Add##NameTo(ClassTo* item)\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_ADD(member, ClassFrom, NameFrom, ClassTo, NameTo) \
}\
void Remove##NameTo(ClassTo* item)\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_REMOVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
void RemoveAll##NameTo()\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_REMOVEALL(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
void DeleteAll##NameTo()\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_DELETEALL(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
void Replace##NameTo(ClassTo* item, ClassTo* newItem)\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_REPLACE(member, ClassFrom, NameFrom, ClassTo, NameTo) \
}\
ClassTo* GetFirst##NameTo() const\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_GETFIRST(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
ClassTo* GetLast##NameTo() const\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_GETLAST(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
ClassTo* GetNext##NameTo(ClassTo* pos) const\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_GETNEXT(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
ClassTo* GetPrev##NameTo(ClassTo* pos) const\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_GETPREV(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
int Get##NameTo##Count() const\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_GETCOUNT(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
ITERATOR_TEMPLATE_NOFILTER_MULTI_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo)
#define RELATION_CRITICAL_AVLTREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
private:\
ClassTo* _top##NameTo;\
int _count##NameTo;\
\
public:\
static CriticalSection _criticalSection##NameTo;\
static CriticalSection& CriticalSection##NameTo() { return _criticalSection##NameTo; }\
\
void Add##NameTo(ClassTo* item);\
void Remove##NameTo(ClassTo* item);\
void RemoveAll##NameTo();\
void DeleteAll##NameTo();\
void Replace##NameTo(ClassTo* item, ClassTo* newItem);\
ClassTo* GetFirst##NameTo() const;\
ClassTo* GetLast##NameTo() const;\
ClassTo* GetNext##NameTo(ClassTo* pos) const;\
ClassTo* GetPrev##NameTo(ClassTo* pos) const;\
int Get##NameTo##Count() const;\
ITERATOR_MULTI_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo)
#define RELATION_NOFILTER_CRITICAL_AVLTREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
private:\
ClassTo* _top##NameTo;\
int _count##NameTo;\
\
public:\
static CriticalSection _criticalSection##NameTo;\
static CriticalSection& CriticalSection##NameTo() { return _criticalSection##NameTo; }\
\
void Add##NameTo(ClassTo* item);\
void Remove##NameTo(ClassTo* item);\
void RemoveAll##NameTo();\
void DeleteAll##NameTo();\
void Replace##NameTo(ClassTo* item, ClassTo* newItem);\
ClassTo* GetFirst##NameTo() const;\
ClassTo* GetLast##NameTo() const;\
ClassTo* GetNext##NameTo(ClassTo* pos) const;\
ClassTo* GetPrev##NameTo(ClassTo* pos) const;\
int Get##NameTo##Count() const;\
ITERATOR_NOFILTER_MULTI_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo)
#define RELATION_CRITICAL_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
public:\
ClassFrom* _ref##NameFrom;\
ClassTo* _parent##NameFrom;\
ClassTo* _left##NameFrom;\
ClassTo* _right##NameFrom;\
int _bal##NameFrom;\
\
public:\
ClassFrom* Get##NameFrom() const { return _ref##NameFrom; };
// defines implementation
#define INIT_CRITICAL_AVLTREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
INIT_AVLTREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define EXIT_CRITICAL_AVLTREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
EXIT_AVLTREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define REPLACE_CRITICAL_AVLTREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
REPLACE_AVLTREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define INIT_CRITICAL_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
INIT_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define EXIT_CRITICAL_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
EXIT_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define REPLACE_CRITICAL_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
REPLACE_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define REMOVE_CRITICAL_AVLTREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
REMOVE_AVLTREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define SAVE_CRITICAL_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
SAVE_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define RESTORE_CRITICAL_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
RESTORE_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define REMOVE_CRITICAL_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
REMOVE_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define CLEANUP_CRITICAL_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
CLEANUP_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define METHODS_CRITICAL_AVLTREE_ACTIVE(member, ClassFrom, NameFrom, ClassTo, NameTo) \
CriticalSection ClassFrom##::_criticalSection##NameTo;\
void ClassFrom##::Add##NameTo(ClassTo* item)\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_ADD(member, ClassFrom, NameFrom, ClassTo, NameTo) \
}\
\
void ClassFrom##::Remove##NameTo(ClassTo* item)\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_REMOVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
\
void ClassFrom##::RemoveAll##NameTo()\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_REMOVEALL(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
\
void ClassFrom##::DeleteAll##NameTo()\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_DELETEALL(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
\
void ClassFrom##::Replace##NameTo(ClassTo* item, ClassTo* newItem)\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_REPLACE(member, ClassFrom, NameFrom, ClassTo, NameTo) \
}\
\
ClassTo* ClassFrom##::GetFirst##NameTo() const\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_GETFIRST(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
\
ClassTo* ClassFrom##::GetLast##NameTo() const\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_GETLAST(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
\
ClassTo* ClassFrom##::GetNext##NameTo(ClassTo* pos) const\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_GETNEXT(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
\
ClassTo* ClassFrom##::GetPrev##NameTo(ClassTo* pos) const\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_GETPREV(ClassFrom, NameFrom, ClassTo, NameTo) \
}\
\
int ClassFrom##::Get##NameTo##Count() const\
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
METHOD_AVLTREE_GETCOUNT(ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define METHODS_CRITICAL_AVLTREE_PASSIVE(ClassFrom, NameFrom, ClassTo, NameTo)
#define BODY_CRITICAL_AVLTREE_FIND(member, value, ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
BODY_AVLTREE_FIND(member, value, ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define BODY_CRITICAL_AVLTREE_FINDREVERSE(member, value, ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
BODY_AVLTREE_FINDREVERSE(member, value, ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define BODY_CRITICAL_AVLTREE_FINDEQUALORSMALLER(member, value, ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
BODY_AVLTREE_FINDEQUALORSMALLER(member, value, ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define BODY_CRITICAL_AVLTREE_FINDEQUALORBIGGER(member, value, ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
BODY_AVLTREE_FINDEQUALORBIGGER(member, value, ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define WRITE_CRITICAL_AVLTREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
WRITE_AVLTREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}
#define READ_CRITICAL_AVLTREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
{\
CriticalSectionLock lock(ClassFrom::CriticalSection##NameTo());\
READ_AVLTREE_ACTIVE(ClassFrom, NameFrom, ClassTo, NameTo) \
}
#endif